import {
  Component,
  Input,
  Output,
  EventEmitter,
  OnInit
} from "@angular/core";
import { NzNotificationService } from "ng-zorro-antd";
import { HttpServcie } from "../../../../service/http.service";
import {
  FormBuilder,
  FormGroup,
} from "@angular/forms";

import { Config } from "../../../../service/config";

@Component({
  selector: "elevator-noowner-modify",
  templateUrl: "elevator-noowner-modify.html",
  styleUrls: ["elevator-noowner-modify.scss"]
})
/**
 * 电梯信息修改
 */
export class ElevatotNoownerModifyPage implements OnInit{
  // 使用单位Id
  public usedPartyId:any;
  //维保单位
  public maintenanceId:any;
  // 使用单位下拉的隐藏标志
  public openData:boolean=false;
  // 维保单位下拉的隐藏标志
  public openData2:boolean=false;
  validateForm: FormGroup;
  isSpinning: boolean = false;
  @Input()
  inValue: any = {};
  data:any = [];
  // 定义父子传值事件
  @Output("outPut")
  public outPut = new EventEmitter();

  companyNamePep :any; //使用名称
  companyNamePep2 :any;//维保单位
  //机构的集合
  partyList: any = [];
  partyList2: any =[];
  config: any = Config;

  constructor(
    private fb: FormBuilder,
    private httpServcie: HttpServcie,
    private _notification: NzNotificationService
  ) { }

  ngOnInit() {

  }
  queryData($event) {
    let ids = this.inValue.join(",");
    if(this.usedPartyId == null && this.maintenanceId == null){
      this._notification.create("error", "失败提示", "至少选择一个使用单位或者维保单位！");
      return ;
    }
    this.isSpinning = true;
    let ob = this.httpServcie.noownerElevatorUpdate({"usedPartyId":this.usedPartyId,"maintenanceId":this.maintenanceId,'ids':ids});
    ob.subscribe(data => {
      this.isSpinning = false;
      if (data.status == 200) {
        this._notification.create("success", "成功提示", "修改成功");
        this.outPut.emit($event);
      } else {
        this._notification.create("error", "失败提示", data.message);
        return;
      }
    });
  }
  /**
   * 查询使用单位名称
   * */
  queryUseCompanyName(){
    if(this.companyNamePep ==null || this.companyNamePep==''){
      this._notification.create("warning", "警告提示", "请输入使用单位名称！");
      return;
    }
    this.httpServcie
      .queryUseCompanyNameList({companyNamePep:this.companyNamePep})
      .subscribe(data =>{
        if(data.status =="200"){
          this.partyList = data.data;
          if(this.partyList.length>0 && this.partyList !=null ){
            this.openData = true;
          }else{
            this.openData = false;
          }
          this.companyNamePep="";
          console.log(data.data)
        }  else {
          this._notification.create("error", "错误提示", data.message);
        }
      })
  }

  /**
   * 查询维保单位名称
   * */
  queryMaintenanceCompanyNameList(){
    if(this.companyNamePep2 ==null || this.companyNamePep2==''){
      this._notification.create("warning", "警告提示", "请输入维保单位名称！");
      return;
    }
    this.httpServcie
      .queryMaintenanceCompanyNameList({companyNamePep2:this.companyNamePep2})
      .subscribe(data =>{
        if(data.status =="200"){
          this.partyList2 = data.data;
          if(this.partyList2.length>0 && this.partyList2 !=null ){
            this.openData2 = true;
          }else{
            this.openData2 = false;
          }
          this.companyNamePep2="";
          console.log(data.data)
        }  else {
          this._notification.create("error", "错误提示", data.message);
        }

      })
  }
}
